/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.cpu.z80;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Pins;
import com.dustedpixels.cirt.model.core.Script;

/**
 * 16-bit increment/decrement circuit.
 * 
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class IncDec16 {
  @In @Pins(16) public int in;
  @In public boolean decOp;
  @Out @Pins(16) public int out;
  
  @Script
  public void update() {
    if (decOp) {
      out = (in - 1) & 0xFFFF;
    } else {
      out = (in + 1) & 0xFFFF;
    }
  }
}
